package com.ybt.heartratem.logic.data.http;


import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.ybt.heartratem.common.entity.ClassInfo;
import com.ybt.heartratem.common.entity.StudentInfo;
import com.ybt.heartratem.common.entity.TeacherInfo;
import com.ybt.heartratem.logic.data.http.service.AASApiService;
import com.ybt.heartratem.logic.data.http.service.entry.AASRequestBody;

import java.util.List;

import io.reactivex.Observable;
import me.goldze.mvvmhabit.http.BaseResponse;
import me.goldze.mvvmhabit.http.UploadParam;
import okhttp3.ResponseBody;

/**
 * Http 数据源接口实现
 */
public class AASDataSourceImpl implements AASDataSource {
    private AASApiService apiService;
    private volatile static AASDataSourceImpl INSTANCE = null;

    public static AASDataSourceImpl getInstance(AASApiService apiService) {
        if (INSTANCE == null) {
            synchronized (AASDataSourceImpl.class) {
                if (INSTANCE == null) {
                    INSTANCE = new AASDataSourceImpl(apiService);
                }
            }
        }
        return INSTANCE;
    }

    public static void destroyInstance() {
        INSTANCE = null;
    }

    private AASDataSourceImpl(AASApiService apiService) {
        this.apiService = apiService;
    }

    @Override
    public Observable<BaseResponse<List<ClassInfo>>> getClassList(String SchoolID) {
        return apiService.getClassList(SchoolID);
    }

    @Override
    public Observable<BaseResponse<List<TeacherInfo>>> GetEmployeeList(String SchoolID) {
        return apiService.GetEmployeeList(SchoolID);
    }

    @Override
    public Observable<BaseResponse<List<StudentInfo>>> getStudentList(String SchoolID, int ClassID) {
        return apiService.getStudentList(SchoolID, ClassID);
    }

    @Override
    public Observable<UploadParam> getOssSignData(String FileName) {
        return apiService.getOssSignData(FileName);
    }


    @Override
    public Observable<JsonObject> getRecordList(int schoolID, int ModelType, int PageIndex, int PageSize) {
        return apiService.getRecordList(schoolID, ModelType, PageIndex, PageSize);
    }

    @Override
    public Observable<JsonObject> getRecordByID(int ID) {
        return apiService.getRecordByID(ID);
    }

    @Override
    public Observable<ResponseBody> AddRecord(AASRequestBody body) {
        return apiService.AddRecord(body);
    }

    @Override
    public Observable<ResponseBody> UpdateRecord(AASRequestBody body) {
        return apiService.UpdateRecord(body);
    }

    @Override
    public Observable<ResponseBody> DeleteRecord(int ID) {
        return apiService.DeleteRecord(ID);
    }

    @Override
    public Observable<BaseResponse<List<TeacherInfo>>> GetEmployeeList(String SchoolID, int RoleID) {
        return apiService.GetEmployeeList(SchoolID, RoleID);
    }

    @Override
    public Observable<JsonArray> getFoodBook(String SchoolID, String TypeOf, String DateFrom, String DateTo) {
        return apiService.getFoodBook(SchoolID,TypeOf,DateFrom,DateTo);
    }

    @Override
    public Observable<JsonObject> getSchoolInfo(int SchoolID) {
        return apiService.getSchoolInfo(SchoolID);
    }

}
